﻿$(function () {
    $.kish.getAllTop = {};
    $.extend($.kish.getAllTop, {

        //********************************//
        //set basid details
        initializing: function () {
            $.kish.getAllTop.getAllTop(20);
            $.Jahanutility.togglePanels($("#CarSearchHeader"), $(".CarSearchHeader"));
            $.Jahanutility.togglePanels($("#carstoreSearchHeader"), $(".carstoreSearchHeader"));
            $.Jahanutility.togglePanels($("#serivceSearchHeader"), $(".serivceSearchHeader"));
        },

        //**********************************************************
        getAllTop: function (TopCount) {
            $('#submit').attr('disabled', 'disabled');
            $.ajax({
                'type': 'POST',
                'url': '../../KishCar/Services/CarAnn.svc/GetTopAll',
                'data': JSON.stringify({ Count: TopCount }),
                'contentType': 'application/json; charset=utf-8',
                'dataType': 'json',
                'success': function (data) {

                    if (data['d'] == null || data['d'].length == 0) {
                        //                        $.kish.message.getErrorMessage("15");
                    }
                    else {

                        //*************Fill top cars announcement *************
                        if (data['d'].Car != null && data['d'].Car.length > 0) {
                            $('#carResult').html('');
                            for (var i = 0; i < data['d'].Car.length; i++) {
                                var price = $.trim(data['d'].Car[i].Price);
                                var path = '../Images/carNoPhoto.gif';
                                if (data['d'].Car[i].CarImages[0] != null) {
                                    var relatedPath = (data['d'].Car[i].CarImages[0].Path);
                                    path = '../' + relatedPath.replace('~', '..');
                                }
                                var x = '<div class="three columns isotope-item ">' +
                                        '<a class="portfolio-item isotope " href="CarDetails.aspx?ID=' + data['d'].Car[i].ID + '">' +
                                            '<figure>' +
                                            '<div class="crop">' +
                                                '<img alt="" src="' + path + '">' +
                                            '</div>' +
						                        '<figcaption class="item-description">' +
							                        '<h5>' + data['d'].Car[i].Model.Code + ' ' + data['d'].Car[i].Model.Brand.Code + '</h5>' +
                                //							                        '<span>' + $.trim(data['d'][i].Color.Code) + '</span>' + ' ' +
                                //                                                    '<span>' + $.trim(data['d'][i].ProductYear) + '</span>' +
                                                  '<span >تومان </span>' + '<span>' + price + '</span>' +
                                                 '</figcaption>' +
					                       '</figure>' +
                                        '</a>' +
                                    '</div>';
                                $('#carResult').append(x);
                            };
                        };

                        //*************Fill top stores announcement *************
                        if (data['d'].CarStore != null && data['d'].CarStore.length > 0) {
                            $('#carstoreResult').html('');
                            for (var i = 0; i < data['d'].CarStore.length; i++) {
                                var tel = $.trim(data['d'].CarStore[i].Telephone);
                                var path = '../Images/carstoreNoPhoto.gif';
                                if (data['d'].CarStore[i].File != null) {
                                    var relatedPath = (data['d'].CarStore[i].File.Path);
                                    path = '../' + relatedPath.replace('~', '..');
                                }
                                var x = '<div class="three columns isotope-item ">' +
                                        '<a class="portfolio-item isotope " href="CarDetails.aspx?ID=' + data['d'].CarStore[i].ID + '">' +
                                            '<figure>' +
                                            '<div class="crop">' +
                                                '<img alt="" src="' + path + '">' +
                                            '</div>' +
						                        '<figcaption class="item-description">' +
							                        '<h5>' + data['d'].CarStore[i].Name + '</h5>' +
                                                (tel.length > 0 ? '<span > تلفن </span>' + '<span>' + tel + '</span>' : '') +
                                                 '</figcaption>' +
					                       '</figure>' +
                                        '</a>' +
                                    '</div>';
                                $('#carstoreResult').append(x);
                            };
                        };
                        //*************Fill top  services announcement *************
                        if (data['d'].ServiceCenter != null && data['d'].ServiceCenter.length > 0) {
                            $('#serviceResult').html('');
                            for (var i = 0; i < data['d'].ServiceCenter.length; i++) {
                                var tel = $.trim(data['d'].ServiceCenter[i].Telephone);

                                var path = '../Images/serviceNoPhoto.gif';
                                if (data['d'].ServiceCenter[i].File != null) {
                                    var relatedPath = (data['d'][i].ServiceCenter.File.Path);
                                    path = '../' + relatedPath.replace('~', '..');
                                }
                                var x = '<div class="three columns isotope-item ">' +
                                        '<a class="portfolio-item isotope " href="CarDetails.aspx?ID=' + data['d'].ServiceCenter[i].ID + '">' +
                                            '<figure>' +
                                            '<div class="crop">' +
                                                '<img alt="" src="' + path + '">' +
                                            '</div>' +
						                        '<figcaption class="item-description">' +
							                        '<h5>' + data['d'].ServiceCenter[i].Name + '</h5>' +
                                                     (tel.length > 0 ? '<span > تلفن </span>' + '<span>' + tel + '</span>' : '') +
                                                '</figcaption>' +
					                       '</figure>' +
                                        '</a>' +
                                    '</div>';
                                $('#serviceResult').append(x);
                            };
                        };

                    };
                },
                'error': function (error) {

                }
            });
        }

    });
    $.kish.getAllTop.initializing();
});



